﻿@using ST = EmoneyWeiXinCommon.StringTools;
@{
    ViewBag.Title = "素材发布列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@ST.GetStaticFile("My97DatePicker/skin/WdatePicker.css")" rel="stylesheet" />
<script src="@ST.GetStaticFile("My97DatePicker/WdatePicker.js")"></script>

<script type="text/javascript">
    var weixinid = "";
    var pageIndex = 1;
    var pageSize = 10;
    var pageCount = 1;
    var totalCount = 0;
    $(document).ready(function () {
        bindMemuType("pType", "@ST.GetTrendsFile("Report/GetMemuTypeList")",
            function (result)
            {
                if (result == "1")
                {
                    //选择栏目
                    var mvalue = queryString(window.location.href, "ntype");
                    $("#drpNewsType").val(mvalue);
                }
                gotoPage();
            }, "-1");
        $("#btnQuery").click(function () {
            pageIndex = 1;
            pageSize = 10;
            pageCount = 1;
            totalCount = 0;
            gotoPage();
        });
        $("#btnAdd").click(function () {
            window.location.href = "@ST.GetTrendsFile("Report/NewsReportfbEdit?leftid=" + ViewBag.leftid)";
    });
    });

    var ajaxdata = {};
    function gotoPage() {
        ajaxdata["pindex"] = pageIndex;
        ajaxdata["psize"] = pageSize;
        ajaxdata["memutype"] = $("#drpNewsType").val();
        ajaxdata["pubdate1"] = $("#txtStart").val();
        ajaxdata["pubdate2"] = $("#txtEnd").val();;
        $.ajax({
            url: "@ST.GetTrendsFile("Report/QueryNewsReportfbList")",
                type: "POST",
                async: true,
                data: ajaxdata,
                beforeSend: function () {
                    //showLoading();
                },
                complete: function () {
                    //iddenLoading();
                },
                success: function (data) {
                    if (data != "" && data != null && data != undefined) {
                        var arrData = data.split("^");
                        totalCount = arrData[0];
                        data = arrData[1];
                        var d = eval(data);
                        var html = "";
                        if (d != "" && d != null && d != undefined) {
                            for (var i = 0; i < d.length; i++) {
                                html += "<tr>";
                                html += getTxtTd(d[i]["ID"]) + '<td><span style="text-align:left">' + subStraddpoint(d[i]["title"], 12) + '</span></td>' + getTxtTd(d[i]["mtitle"]) + getTxtTd(d[i]["pubDate"].replace(/T/g, " ").substring(0, 10));
                                html += getTxtTd(d[i]["updatetime"].replace(/T/g, " ").substring(0, 19)) + getValidTd(d[i]["ID"], d[i]["ValidName"], d[i]["isvalid"]) + getTxtTd(d[i]["PubStatusName"]) + getTxtTd(d[i]["PubMethod"]);
                                html += getTxtTd(d[i]["source"]) + getTxtTd(d[i]["Author"]);
                                html += "<td>" + getXqA(d[i]["ID"]) + getEditA(d[i]["ID"]) + "</td>";
                                html += '</tr>';
                            }
                        }
                        $("#dvList").html(html);
                        PageCountHtml();
                    }
                    else {
                        $("#dvList").html("没有查询到相关数据！");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(errorThrown);
                }
            });
        }

        function getTxtTd(s) {
            return '<td><span>' + s + '</span></td>';
        }
        function getXqA(id) {
            var hrefvalue = "@ST.GetTrendsFile("Report/NewsReportfbDetail")" + "?id=" + id;
            return '<a class="manage_bottom_font blue" href="' + hrefvalue + '"  target="_blank">浏览</a>';
        };
        function getEditA(id) {
            var hrefvalue = "@ST.GetTrendsFile("Report/NewsReportfbEdit")" + "?id=" + id + "&leftid=@ViewBag.leftid";
        return '<a class="manage_bottom_font blue" href="' + hrefvalue + '" style="display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(3, ViewBag.leftid))">编辑</a>';
    };
    function getValidTd(id, validname, isvalid) {
        return "<td><a class=\"manage_bottom_font red\" onclick=\"operate('-1','" + id + "','" + isvalid + "')\">" + validname + "</a></td>";
    }

    function subStraddpoint(str, blLen) {
        if (str.length > blLen) {
            return str.substring(0, blLen) + "...";
        }
        else return str;
    }

    //编辑，删除，关闭操作
    function operate(op, id, isvalid) {
        $.ajax({
            url: "@ST.GetTrendsFile("Report/UpdateValidNewsReportfb")",
            type: "POST",
            async: true,
            data: { op: op, id: id, isvalid: isvalid },
            beforeSend: function () {
                //showLoading();
            },
            complete: function () {
                // hiddenLoading();
            },
            success: function (data) {
                if (data == "1") {
                    gotoPage();
                    //alert("操作成功!");

                } else alert(data);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(errorThrown);
            }
        });
    };



    //翻页
    function PageCountHtml() {
        pageCount = Math.ceil(totalCount / pageSize);
        if (pageCount == 0) {
            pageCount = 1;
        }
        $("#manage_page").html(PageHtml(pageIndex, pageCount));
        $("#manage_page .manage_page_right").click(function () {
            pageIndex = parseInt($("#txtPageNum").val()) + parseInt($(this).attr("tname"));
            $("#manage_page").html(PageHtml(pageIndex, pageCount));
            gotoPage();
        });
        $("#manage_page .tiaozhuan").click(function () {
            var pageNum = $("#txtPageNum").val();
            try {
                pageIndex = parseInt(pageNum);
            } catch (e) {
                alert("请输入数字");
                return false;
            }

            if (pageNum > 0 && pageNum <= pageCount) {
                $("#manage_page").html(PageHtml(pageIndex, pageCount));
                gotoPage();
            }
            else {
                alert("当前数字超出范围");
                return false;
            }
        });
    }
</script>
<div class="right">
    <h3>素材发布列表</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <div class="manage_register">
                <p id="pType">
                </p>
                <p>
                    <span>发布时间：</span>
                    <input type="text" id="txtStart" onfocus="WdatePicker()" class="manage_register_text">
                    <span class="manage_register_font">至</span><input style="display: none" id="hidid" type="text">
                    <input type="text" id="txtEnd" onfocus="WdatePicker()" class="manage_register_text">
                </p>
            </div>
            <p class="manage_add">
                <a id="btnQuery">查询</a>
                <a id="btnAdd" style="display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(2, ViewBag.leftid))">添加</a>
            </p>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_bottom-->
        <div class="manage_bottom">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th><span>编号</span></th>
                    <th><span>标题</span></th>
                    <th><span>栏目</span></th>
                    <th><span>发布时间</span></th>
                    <th><span>更新时间</span></th>
                    <th><span>是否有效</span></th>
                    <th><span>是否发布</span></th>
                    <th><span>自动导入/手动发布</span></th>
                    <th><span>来源</span></th>
                    <th><span>发布者</span></th>
                    <th><span>操作</span></th>
                </tr>
                <tbody id="dvList"></tbody>
            </table>
            <div class="manage_page" id="manage_page">
            </div>
        </div>
        <!--manage_bottom end-->
    </div>
    <!--manage end-->

</div>
